//导航
$(function() {
	var $obj = $('.menu ul');
	$obj.find('li').on('mouseenter', function() {
		$(this).addClass("intro");
	});
	$obj.find('li').on('mouseleave', function() {
		$(this).removeClass("intro");
	})

	//导航展开
	$('#men_pro').on('mouseenter', function() {
		$('#menu_hover_bg').stop().animate({
			height: '610px'
		}, 500);
		$('#men_pro .sub_menu').stop().animate({
			height: '610px'
		}, 600);
	})
	$('#men_pro').on('mouseleave', function() {
		$('#menu_hover_bg').stop().animate({
			height: '0'
		}, 600);
		$('#men_pro .sub_menu').stop().animate({
			height: '0'
		}, 500);
	})
	$('#men_sol').on('mouseenter', function() {
		$('#menu_hover_bg').stop().animate({
			height: '340px'
		}, 500);
		$('#men_sol .sub_menu').stop().animate({
			height: '340px'
		}, 600);
	})
	$('#men_sol').on('mouseleave', function() {
		$('#menu_hover_bg').stop().animate({
			height: '0'
		}, 600);
		$('#men_sol .sub_menu').stop().animate({
			height: '0'
		}, 500);
	})
	$('#men_fuwu').on('mouseenter', function() {
		$('#menu_hover_bg').stop().animate({
			height: '340px'
		}, 500);
		$('#men_fuwu .sub_menu').stop().animate({
			height: '340px'
		}, 600);
	})
	$('#men_fuwu').on('mouseleave', function() {
		$('#menu_hover_bg').stop().animate({
			height: '0'
		}, 600);
		$('#men_fuwu .sub_menu').stop().animate({
			height: '0'
		}, 500);
	})
	//服务分类选项卡
    $('#men_fuwu .category li').mouseover(function() {
        var i = $(this).index();
        $(this).addClass('active').siblings().removeClass('active');
        $('#men_fuwu .content .cont_list').eq(i).show().siblings().hide();
    });				
});
//轮播图
var main_swiper = new Swiper('.swiper-banner.swiper-container', {
    direction: 'horizontal',
    slidesPerView: 1,
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    }
});

//行业模板
$(function(){
	$('.xyg-template .category ul li').click(function(){
		var colFlag = $(this).attr("data-id");
        setTemplate(colFlag);
		$(this).addClass('active').siblings().removeClass('active');
	})
})

function setTemplate(colFlag) {
    acceptXygProductListByColFlagTagFlag(1,colFlag,"frist_show",5,function(data){
        $(".xyg-template .content ul").html("");
        if(colFlag=="wzmb"){
            $(".xyg-template .content").addClass("dnsc");
		}else {
            $(".xyg-template .content").removeClass("dnsc");
		}
        if (data != null && data.length > 0) {
            data.forEach(function (item,key,mapObj) {
                var str='<li><div class="img"><img src="'+item.images+'"/>'+
                    '</div><div class="bg"><img src="'+item.coverImage+'"/>'+
                    '</div></li>';
                if(colFlag=="wzmb"){
                    str='<li><div class="img"><img src="'+item.images+'"/> '+
                        '</div><div class="bg"><a href="/web/pc/productTitle?productId='+item.id+'&navId='+navId+'" target="_blank"><img src="'+item.coverImage+'"  style="cursor:pointer;"/></a>'+
                        '</div></li>';
                }

                $(".xyg-template .content ul").append(str);
            });
        }
    });
}
//新闻模板
$(document).ready(function(){
	//设计案例切换
	$('.xyg-new-box .new-telst li').mouseover(function(){
        var liindex = $('.new-telst li').index(this);
        var colFlag = $(this).attr("data-id");
        setNews(colFlag);
		$(this).addClass('newon').siblings().removeClass('newon');
        var liWidth = $('.new-telst li').width();
        $('.newtel .new-telst p').stop(false,true).animate({'left' : liindex * liWidth + 'px'},300);
	});
	
});

function setNews(colFlag) {
    acceptXygArticleListByColFlagTagFlag(1,colFlag,"wz_frist_show",7,function(data){
        $("#newsShow").html("");
        if (data != null && data.length > 0) {
        	var i=0;
            var str='<ul class="new-lst-cn">';
            data.forEach(function (item,key,mapObj) {

            	if(i==0){
					str+='<li class="new-cnlf"><p class="newlf-img">'+
                        '<img src="'+item.thumImage+'" width="370" height="147">'+
                        '</p><p class="newlf-tel">'+
                        '<a href="/web/pc/descTitle?articleId='+item.id+'&navId='+navId+'" target="_blank">'+item.title+'</a>'+
                    '</p><p class="newlf-tx">'+item.description+'</p></li><li class="new-cnrf"> <div class="newrf-lst"><dl>';
				}else{
                    str+='<dd><p class="new-rq">'+
                        '<span>'+timeStamp2String(item.createTime,"dd")+'</span>'+timeStamp2String(item.createTime,"yyyy-MM")+'</p>'+
                        '<p class="newrf-tx font-grade-one">'+
                        '<a href="/web/pc/descTitle?articleId='+item.id+'&navId='+navId+'" target="_blank">'+item.title+'</a>'+
					'<span class="font-grade-two">'+item.description+'</span></p></dd>';
				}
                i++;

            });
            str+='</dl></div></li><div class="clear"></div></ul>';
            $("#newsShow").append(str);
        }
    });
}
var offset = 80;
$(window).scroll(function() {
	($(this).scrollTop() > offset) ? $('.xyg-menu').addClass('xyg-menu-fixed'): $('.xyg-menu').removeClass('xyg-menu-fixed');
})

function timeStamp2String(time,type){
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    if(type=="yyyy"){
    	return year;
	}else  if(type=="yyyy-MM"){
        return year + "-" + month ;
    }else  if(type=="dd"){
        return date ;
    }else{

        return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
	}

}